using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
using System.Windows.Forms;
namespace Lifter.Gui.Monitor.Controls
{
    public class SCStateControl : BaseControl
    {
        public enum SCSTATE
        {
            SCINIT = 1,
            PAUSED,
            PAUSING,
            AUTO
        }
        private Timer timer = new Timer();
        private int tickCount = 0;
        private SCStateControl.SCSTATE scState = SCStateControl.SCSTATE.SCINIT;
        private int borderWith = 0;
        private int interval = 500;
        private IContainer components = null;
        public int BorderWith
        {
            get
            {
                return this.borderWith;
            }
            set
            {
                this.borderWith = value;
                base.Invalidate();
            }
        }
        public SCStateControl.SCSTATE ScState
        {
            get
            {
                return this.scState;
            }
            set
            {
                this.scState = value;
                base.Invalidate();
            }
        }
        public int Interval
        {
            get
            {
                return this.interval;
            }
            set
            {
                this.interval = value;
                base.Invalidate();
            }
        }
        public SCStateControl()
        {
            this.InitializeComponent();
            this.timer.Enabled = false;
            this.timer.Interval = 500;
            this.timer.Tick += new EventHandler(this.Timer_Tick);
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            this.DrawBody(e.Graphics);
        }
        private void DrawBody(Graphics g)
        {
            if (g == null)
            {
                g = base.CreateGraphics();
            }
            g.SmoothingMode = SmoothingMode.HighQuality;
            g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
            Color fillColor = Color.FromArgb(85, 85, 85);
            Brush brush2 = Brushes.Black;
            string s = "";
            switch (this.scState)
            {
                case SCStateControl.SCSTATE.SCINIT:
                    s = "SCINIT";
                    brush2 = Brushes.Gray;
                    break;
                case SCStateControl.SCSTATE.PAUSED:
                    s = "PAUSED";
                    brush2 = Brushes.Red;
                    break;
                case SCStateControl.SCSTATE.PAUSING:
                    s = "PAUSING";
                    brush2 = Brushes.Crimson;
                    break;
                case SCStateControl.SCSTATE.AUTO:
                    s = "AUTO";
                    brush2 = Brushes.Green;
                    break;
            }
            Rectangle rect = new Rectangle(this.borderWith, this.borderWith, base.Width - this.borderWith * 2, base.Height - this.borderWith * 2);
            g.FillRectangle(new SolidBrush(fillColor), rect);
            Font font = new Font("Tahoma", 12f, FontStyle.Bold);
            StringFormat stringFormat = new StringFormat();
            stringFormat.Alignment = StringAlignment.Center;
            stringFormat.LineAlignment = StringAlignment.Center;
            g.DrawString(s, font, brush2, new RectangleF(this.borderWith, this.borderWith, base.Width - this.borderWith * 2, base.Height - this.borderWith * 2), stringFormat);
        }
        private void Timer_Tick(object sender, EventArgs e)
        {
            if (this.tickCount == 1)
            {
                this.tickCount = 0;
                base.Invalidate();
            }
            else
            {
                this.tickCount = 1;
                base.Invalidate();
            }
        }
        protected override void Dispose(bool disposing)
        {
            if (disposing && this.components != null)
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }
        private void InitializeComponent()
        {
        }
    }
}
